<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     default_iphone
 * @copyright   Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Product list template
 *
 * @see Mage_Catalog_Block_Product_List
 */
?>
<?php
$_productCollection = $this->getLoadedProductCollection();

//echo $_productCollection->getSelect();

$_newProductCollection = Mage::getModel('catalog/product')->getCollection()
            ->setPage(1,2)
            ->setOrder("entity_id")
            ->addAttributeToSelect('*');
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_newProductCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($_newProductCollection);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($_newProductCollection);
$_newProductCollection->getSelect()->group('e.entity_id');


//echo $_productCollection->getSelect();
//echo get_class($this);

$_currentCategory = Mage::registry('current_category');
$catalogMod  = Mage::getModel('catalog/category');
$_helper = $this->helper('catalog/output');
$_catalogHp  = $this->helper('catalog/category');
$zgbHelper = Mage::helper('zgb');
//$_productCategory = $catalogMod->load(Silk_Store_Config_Store::PRODUCT_ALL_CATEGORY_ID);
?>
<?php if(!$_productCollection->count()): ?>
    <div class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></div>
<?php else: ?>
    <div class="category-products-main">
     <div class="category-products-top">
         <ul>
             <a href="#menu"><li><span><?php echo $this->__('全部分类') ?></span><i class="triangle-icon"></i></li></a>
             <li id="category-filter"><span><?php echo $this->__('品牌') ?></span><i class="triangle-icon"></i></li>
             <li id="category-sort"><span><?php echo $this->__('排序') ?></span><i class="triangle-icon"></i></li>
         </ul>
     </div>
     <div class="category-products-filtrate"></div>
     <div class="category-products-filtrate2"></div>
     <div class="category-products-content">
        
        <div class="Regional-filter">
            <?php echo $this->getChildHtml('catalog.filter')?>
        </div>
        <div class="Sorting-filter">
            <?php echo $this->getToolbarHtml() ?>
            <span><a title="<?php echo $this->__('Reset') ?>" href="<?php echo $_catalogHp->getCategoryUrl($_currentCategory) ?>"><?php echo $this->__('Reset') ?></a></span>
        </div>
    </div>
<div class="category-products">
    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <ul class="c-list">
    <?php
        $_rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
        $_allCategoryId = Mage::getModel("catalog/category")->load($_rootCategoryId)
                            ->getChildren();
        $_currentCategoryId = Mage::app()->getRequest()->getParam("id");
        $_currentOrder = Mage::app()->getRequest()->getParam("order");
        $_currentBrand = Mage::app()->getRequest()->getParam("brand");
        $_currentPageNum = Mage::getBlockSingleton('page/html_pager')->getCurrentPage();
        $_newIds = array();
    ?>
    <?php if($_currentCategoryId === $_allCategoryId && !($_currentOrder.$_currentBrand) && $_currentPageNum === 1): ?>
        <?php foreach($_newProductCollection as $_product):?>
            <?php $_newIds[] = $_product->getId(); ?>
            <li>
            <div class="wrap">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                    <div class="product-image">
                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image'); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                        <?php if($zgbHelper->hasTag($_product)): ?>
                            <div class="product-sale-tag">
                                <img src="<?php echo $zgbHelper->getSaleTagUrl($_product, $this->getSkinUrl('images')); ?>" alt="" />
                            </div>
                        <?php endif; ?>
                    </div>
                </a>
                <div class="product-shop">
                    <div>
                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                            <p><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></p>
                        </a>

                        <?php 
                            //$tags = Mage::helper('zgb')->getProductInfoTags($_product);
                            $tags = $_product->getPromotion();
                            if($tags):
                        ?>
                        <div class="product-info-tags-wrapper">
                        <?php foreach($tags as $tag):?>
                            <span class="product-info-tags" ><?php echo $tag; ?></span>
                        <?php endforeach; ?>
                        </div>
                        <?php endif; ?>

                        <?php echo $this->getPriceHtml($_product, true) ?>
                            <div class="addToCart" data-action="<?php echo $this->getUrl('checkout/cart/addAjax',array('product'=>$_product->getId())); ?>">
                                <span class="fa fa-minus num-down" id="num-down"></span>
                                <span class="qty-span"><input type="number" name="qty"  class="pnum" id="qty"/></span>
                                <span class="fa fa-plus num-up" id="num-up"></span>
                                <button class="add-to-cart-button cart-icon"><i class="fa fa-cart-plus"></i></button>
                            </div>
                    </div>
                </div>
            </div>
        </li>
        <?php endforeach ?>
    <?php endif ?>
        <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if(in_array($_product->getId(),$_newIds)) continue;?>
        <li>
            <div class="wrap">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                    <div class="product-image">
                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image'); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                        <?php if($zgbHelper->hasTag($_product)): ?>
                            <div class="product-sale-tag">
                                <img src="<?php echo $zgbHelper->getSaleTagUrl($_product, $this->getSkinUrl('images')); ?>" alt="" />
                            </div>
                        <?php endif; ?>
                    </div>
                </a>
                <div class="product-shop">
                    <div>
                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
                            <p><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></p>
                        </a>

                        <?php 
                            //$tags = Mage::helper('zgb')->getProductInfoTags($_product);
                            $tags = $_product->getPromotion();
                            if($tags):
                        ?>
                        <div class="product-info-tags-wrapper">
                        <?php //foreach($tags as $tag):?>
                            <span class="product-info-tags" ><?php echo $tags; ?></span>
                        <?php //endforeach; ?>
                        </div>
                        <?php endif; ?>

                        <?php echo $this->getPriceHtml($_product, true) ?>
                            <div class="addToCart" data-action="<?php echo $this->getUrl('checkout/cart/addAjax/',array('product'=>$_product->getId())); ?>">
                                <span class="fa fa-minus num-down" id="num-down"></span>
                                <span class="qty-span"><input type="number"  name="qty" class="pnum" id="qty"/></span>
                                <span class="fa fa-plus num-up" id="num-up"></span>
                                <button class="add-to-cart-button cart-icon"><i class="fa fa-cart-plus"></i></button>
                            </div>
                    </div>
                </div>
            </div>
        </li>
    <?php endforeach ?>
</ul>
</div>
</div>
<?php endif; ?>

